package com.nsoft.thickclient.trackMove.account;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import com.nsoft.server.serviceImpl.FacadeFactoryImpl;
import com.nsoft.thickclient.controller.ApplicationController;
import com.nsoft.thickclient.trackMove.intr.account.Account;
import com.nsoft.thickclient.trackMove.search.SearchAction;
import com.nsoft.thickclient.trackMove.search.SearchView;
import com.nsoft.thickclient.trackMove.search.SearchViewController;

public class SearchAccountAction implements SearchAction<Account> {

	public void delete(Account bean) {
		// TODO Auto-generated method stub

	}

	public void edit(Account bean, ApplicationController applicationController) {
		AccountViewController controller = new AccountViewController(true);
		applicationController.openScreen(controller, new Dimension(800, 550));
		controller.getAccountView().setWorkingBean(bean);
	}

	public Account getNewBean() {
		return new Account();
	}

	public SearchView<Account> getView(SearchViewController<Account> controller) {
		List<Account> list = new ArrayList<Account>();
		for (int i = 0; i < 10; i++) {
			Account account = new Account();
			account.setNumber("Ac 110239" + i * 3);
			account.setName("name -> " + i);
			account.setCurrentBalance(23974.0 + i * 7);
			list.add(account);
		}

		AccountView accountView = new AccountView();
		String[] properties = { "number", "name", "currentBalance" };
		String[] headers = { "Account No", "Name", "current balance" };
		SearchView<Account> searchView = new SearchView<Account>(list,
				properties, headers, accountView, controller);
		return searchView;
	}

	public List<Account> search(Account bean) {
		return FacadeFactoryImpl.getAccountService().searchAccount(bean);
	}

}
